# 参考： https://www.cnblogs.com/superhin/p/13257401.html

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep

service = Service('/usr/local/bin/chromedriver')
service.start()
driver = webdriver.Remote(service.service_url)

def run():
    global driver
    url = 'https://www.baidu.com/'
    # 躲避智能检测
    option = webdriver.ChromeOptions()
    option.add_experimental_option('excludeSwitches', ['enable-automation'])
    option.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=option)
    driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument',
                           {'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
                            })

    driver.get(url)

    driver.find_element('id', 'kw').send_keys('博客园 yanglei_xyz')
    driver.find_element('id', 'su').click()
    sleep(5)

    driver.quit()

if __name__=='__main__':
    run()

